package com.yiwei.hdb.adapter.base;

import android.util.SparseArray;
import android.view.View;

/**
 * Created by WIN7 on 2016/4/13.
 * http://blog.csdn.net/hmily7532361/article/details/18368235
 * 只提供一个静态方法，其实可以加一个私有构造函数防止外部实例化
 */
public class BaseLViewHolder {
    public static <T extends View> T get(View view, int id) {
        SparseArray<View> viewHolder = (SparseArray<View>) view.getTag();
        if (viewHolder == null) {
            viewHolder = new SparseArray<View>();
            view.setTag(viewHolder);
        }
        View childView = viewHolder.get(id);
        if (childView == null) {
            childView = view.findViewById(id);
            viewHolder.put(id, childView);
        }
        return (T) childView;
    }
}
